/**
 * @param {character[][]} board
 * @param {string} word
 * @return {boolean}
 */
 var exist = function(board, word) {
    let rowlength=board.length,collength=board[0].length;
    let ison=new Array(rowlength).fill(0).map(()=>new Array(collength).fill(false));
    console.log(ison);
    for(let i=0;i<rowlength;i++){
        for(let j=0;j<collength;j++){
            if(isword(0,i,j)){
                return true;
            }
        }
    }
    return false;
    function isword(index=0,row,col){
        if(index>=word.length){
            return true;
        }
        if(col<0 || col>=collength || row<0 || row>=rowlength || ison[row][col]){
            return false;
        }
        ison[row][col]=true;
        let res=false;
        if(board[row][col]===word[index]){
            res=isword(index+1,row+1,col)||isword(index+1,row-1,col)||isword(index+1,row,col+1)||isword(index+1,row,col-1);
        }
        ison[row][col]=false;
        return res;
    }
};

console.log(exist([["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
,"ABCCED"));